const hostelsModel = require('../models/hostelsModel')
// 添加宿舍记录
exports.add = async (req, res) => {
    let { building_id, room_id, type, class_id, person_number, teacher, comment } = req.body
    try {
        let results = await hostelsModel.add(building_id, room_id, type, class_id, person_number, teacher, comment)
        console.log(results)
        res.json({ code: 0, msg: "添加宿舍记录成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 宿舍记录删除--软删除
exports.del_f = async (req, res) => {
    let { id } = req.query
    try {
        let results = await hostelsModel.del_f(id)
        console.log(results)
        res.json({ code: 0, msg: "宿舍记录禁用成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
exports.start = async (req, res) => {
    let { id } = req.query
    try {
        let results = await hostelsModel.start(id)
        console.log(results)
        res.json({ code: 0, msg: "宿舍记录启用成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 宿舍记录删除--真删除
exports.del_t = async (req, res) => {
    let { id } = req.query
    try {
        let results = await hostelsModel.del_t(id)
        console.log(results)
        res.json({ code: 0, msg: "宿舍记录删除成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 宿舍的记录获取--get
exports.get = async (req, res) => {
    let { id } = req.query
    try {
        let results = await hostelsModel.get(id)
        console.log(results)
        res.json({ code: 0, msg: "宿舍的记录获取数据成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 宿舍的记录更新数据--set
exports.set = async (req, res) => {
    let { id, building_id, room_id, type, class_id, person_number, teacher, comment } = req.body
    try {
        let results = await hostelsModel.set(id, building_id, room_id, type, class_id, person_number, teacher, comment)
        console.log(results)
        res.json({ code: 0, msg: "宿舍的记录设置数据成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}


// 宿舍中的人员管理--添加宿舍人员
exports.person_add = async (req, res) => {
    let { hostel_id, student_id, bed_space } = req.body
    try {
        let results = await hostelsModel.person_add(hostel_id, student_id, bed_space)
        console.log(results)
        res.json({ code: 0, msg: "添加宿舍人员数据成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 宿舍中的人员管理--宿舍记录删除--软删除
exports.person_del_f = async (req, res) => {
    let { id, hostel_id } = req.query
    try {
        let results = await hostelsModel.person_del_f(Number(id), Number(hostel_id))
        console.log(results)
        res.json({ code: 0, msg: "宿舍中的人员记录删除成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 宿舍中的人员管理--宿舍记录删除--真删除
exports.person_del_t = async (req, res) => {
    let { id } = req.query
    try {
        let results = await hostelsModel.person_del_t(id)
        console.log(results)
        res.json({ code: 0, msg: "宿舍中的人员记录删除成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 宿舍中的人员管理--宿舍的记录获取--get
exports.person_get = async (req, res) => {
    let { id } = req.query
    try {
        let results = await hostelsModel.person_get(id)
        console.log(results)
        res.json({ code: 0, msg: "宿舍中的人员记录获取数据成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}

// 宿舍中的人员管理--修改宿舍人员
exports.person_set = async (req, res) => {
    let { id, hostel_id, student_id, bed_space } = req.body
    try {
        let results = await hostelsModel.person_set(Number(id), hostel_id, student_id, bed_space)
        console.log(results)
        res.json({ code: 0, msg: "更新宿舍人员数据成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}

// 宿舍的记录的列表搜索分页
exports.list = async (req, res) => {
    let { room_id, building_id, class_id, type, program_id, page, page_size } = req.query
    try {
        let results = await hostelsModel.list(room_id, building_id, class_id, type, program_id, Number(page), Number(page_size))
        console.log(results)
        res.json({ code: 0, msg: "宿舍的记录的列表搜索分页获取数据成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}
// 宿舍中的人员列表搜索
exports.person_list = async (req, res) => {
    let { hostel_id, page, page_size } = req.query
    try {
        let results = await hostelsModel.person_list(hostel_id, Number(page), Number(page_size))
        console.log(results)
        res.json({ code: 0, msg: "宿舍中的人员列表搜索获取数据成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}

// 根据传过来的班级id去查找对应的专业
exports.clsToprm = async (req, res) => {
    let { class_id } = req.query
    try {
        let results = await hostelsModel.clsToprmM(Number(class_id))
        console.log(results)
        res.json({ code: 0, msg: "班级id去查找对应的专业获取数据成功！", results })
    } catch (error) {
        console.log(error)
        res.json({ code: 0, msg: error })
    }
}